home *** CD-ROM | disk | FTP | other *** search
- #include <Global.h>
- #include <Commands.h>
- #include <CApplication.h>
- #include <CBartender.h>
- #include <CDataFile.h>
- #include <CDecorator.h>
- #include <CDesktop.h>
- #include <CError.h>
- #include <CPanorama.h>
- #include <CScrollPane.h>
- #include <TBUtilities.h>
- #include "InkDoc.h"
- #include "InkPane.h"
- #include "CWindow.h"
-
- #define WINDculture 500 /* Resource ID for WIND template */
-
- extern CApplication *gApplication; /* The application */
- extern CBartender *gBartender; /* The menu handling object */
- extern CDecorator *gDecorator; /* Window dressing object */
- extern CDesktop *gDesktop; /* The enclosure for all windows */
- extern CBureaucrat *gGopher; /* The current boss in the chain of command */
- extern OSType gSignature; /* The application's signature */
- extern CError *gError; /* The error handling object */
-
- void InkDoc::IEditDoc(CApplication *aSupervisor, Boolean printable) {
- CDocument::IDocument(aSupervisor, printable);
- }
-
- void InkDoc::NewFile(void) {
- BuildWindow(NULL);
- itsWindow->Select();
- }
-
- void InkDoc::OpenFile(SFReply *macSFReply) {
- CDataFile *theFile;
- Handle theData;
- Str63 theName;
- OSErr theError;
- theFile = new(CDataFile);
- itsFile = theFile;
- theFile->IDataFile();
- theFile->SFSpecify(macSFReply);
- theFile->Open(fsRdWrPerm);
- theData = theFile->ReadAll(); /* ReadAll() creates the handle */
- BuildWindow(theData);
- DisposHandle(theData);
- itsFile->GetName(theName);
- itsWindow->SetTitle(theName);
- itsWindow->Select(); /* Don't forget to make the window active */
- }
-
- void InkDoc::BuildWindow (Handle theData) {
- CScrollPane *theScrollPane;
- InkPane *theMainPane;
- Rect margin;
- itsWindow = new(CWindow);
- itsWindow->IWindow(WINDculture, FALSE, gDesktop, this);
- theScrollPane = new(CScrollPane);
- theScrollPane->IScrollPane(itsWindow, this, 10, 10, 0, 0,
- sizELASTIC, sizELASTIC,
- TRUE, TRUE, TRUE);
- theScrollPane->FitToEnclFrame(TRUE, TRUE);
- theMainPane = new(InkPane);
- itsMainPane = theMainPane;
- itsGopher = theMainPane;
- theMainPane->IEditPane(theScrollPane, this);
- theScrollPane->InstallPanorama(theMainPane);
- if (theData)
- theMainPane->SetData(theData);
- gDecorator->PlaceNewWindow(itsWindow);
- }
-
- Handle GetFlatData(List *Data);
-
-
- Boolean InkDoc::DoSave(void) {
- Handle theData;
-
- if (itsFile == NULL)
- return(DoSaveFileAs());
- else {
- theData = GetFlatData(((InkPane*)itsMainPane)->Data);
- ((CDataFile *)itsFile)->WriteAll(theData);
- dirty = FALSE; /* Document is no longer dirty */
- gBartender->DisableCmd(cmdSave);
- return(TRUE); /* Save was successful */
- }
- }
-
- Boolean InkDoc::DoSaveAs(SFReply *macSFReply) {
- if (itsFile != NULL)
- itsFile->Dispose();
- itsFile = new(CDataFile);
- ((CDataFile *)itsFile)->IDataFile();
- itsFile->SFSpecify(macSFReply);
- itsFile->CreateNew(gSignature, 'INKd');
- itsFile->Open(fsRdWrPerm);
- itsWindow->SetTitle(macSFReply->fName);
- return( DoSave() );
- }
-